/*
 * @lc app=leetcode.cn id=53 lang=javascript
 *
 * [53] 最大子序和
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var maxSubArray = function (nums) {
  const len = nums.length;
  let max = Number.MIN_SAFE_INTEGER;

  for (let i = 0; i < len; i++) {
    let sum = nums[i];
    max = Math.max(max, sum);

    for (let j = i + 1; j < len; j++) {
      sum += nums[j];

      if (sum > max) {
        max = sum;
      }
    }
  }

  return max;
};
// @lc code=end

// @after-stub-for-debug-begin
module.exports = maxSubArray;
// @after-stub-for-debug-end
